<template>
    <div class="goodslist-container">
        <router-link class="goods-item" v-for="item in list" :key="item.id" :to="'/home/goodsinfo/'+item.id" tag="div">
            <img :src="item.img_url" alt="">
            <h3 class="title">{{item.title}}</h3>
            <div class="info">
                <p class="price">
                    <span class="now">¥{{item.sell_price}}</span>
                    <span class="old">¥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </router-link>

        <mt-button type="danger" size="large" @click="getmore">加载更多</mt-button>
        
       
    </div>
</template>

<script>
export default {
    data() {
        return{
            pageindex: 1,
            list: [],
        }
    },
    created(){
        this.getgoods();
    },
    methods:{
        getgoods(){
            this.$http.get("api/getgoods/?pageindex"+this.pageindex).then(result=>{
                if(result.body.status === 0){
                    this.list = this.list.concat(result.body.message);
                }
            })
        },
        getmore(){
            this.pageindex++;
            this.getgoods();
        },
    },
}
</script>

<style lang="scss" scoped>
    .goodslist-container{
        display: flex;
        flex-wrap: wrap;
        padding: 7px;
        justify-content: space-between;
        .goods-item{
            width: 49%;
            margin: 5px 0;
            border: 1px solid #ccc;
            box-shadow: 0 0 9px #999;
            padding: 2px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 320px;
            img{
                width: 100%;
            }
            .title{
                font-size: 16px;
                padding: 0 10px;
            }
            .info{
                background-color:rgba(0,0,0,0.1);
                padding: 0 5px;
                .price{
                    padding-top: 5px;
                    margin-bottom: 0;
                    .now{
                        font-size: 16px;
                        color: rgb(226, 44, 44);
                        margin: 0 10px;
                        font-weight: 600;
                    }
                    .old{
                        font-size: 12px;
                        color: rgba(0,0,0,0.4);
                        
                    }
                }
                .sell{
                    font-size: 14px;
                    color: rgb(151, 142, 142);
                    display: flex;
                    justify-content: space-between;
                    margin-bottom: 0;
                    padding: 5px ;
                }
            }   
        }
    }

</style>